home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / cli / CLI_Tools.lha / Exists.c < prev    next >
C/C++ Source or Header  |  1995-02-03  |  3KB  |  122 lines

  1.  
  2. /******************************************************************************
  3.  
  4.     MODULE
  5.     Exists.c
  6.  
  7.     DESCRIPTION
  8.     Get one filename on Commandline
  9.     and write to StdOut if it exists
  10.  
  11.     NOTES
  12.     Kickstart 2.0+ required
  13.     compiles w/ Dice 2.07R - inline-pragmas required
  14.     compiles w/ SAS/C v6.51
  15.  
  16.     BUGS
  17.     We use 'Lock', so Exists fails, if the
  18.     file exists and is exclusively locked
  19.  
  20.     TODO
  21.     Use another way than 'Lock' to determine
  22.     the existance
  23.  
  24.     EXAMPLES
  25.     > Exists Sys:System/CLI
  26.     1
  27.  
  28.     SEE ALSO
  29.  
  30.     INDEX
  31.  
  32.     HISTORY
  33.     03-02-95 b_noll created
  34.  
  35.     AUTHOR
  36.     Bernd Noll, Brunnenstrasse 55, D-67661 Kaiserslautern
  37.     b_noll@informatik.uni-kl.de
  38.  
  39. ******************************************************************************/
  40.  
  41. /**************************************
  42.         Includes
  43. **************************************/
  44.  
  45. #ifndef   EXEC_LIBRARIES_H
  46. # include <exec/libraries.h>
  47. #endif /* EXEC_LIBRARIES_H */
  48.  
  49. #ifndef   CLIB_EXEC_PROTOS_H
  50. # include <clib/exec_protos.h>
  51. #endif /* CLIB_EXEC_PROTOS_H */
  52.  
  53. #ifndef   DOS_DOS_H
  54. # include <dos/dos.h>
  55. #endif /* DOS_DOS_H */
  56.  
  57. #ifndef   CLIB_DOS_PROTOS_H
  58. # include <clib/dos_protos.h>
  59. #endif /* CLIB_DOS_PROTOS_H */
  60.  
  61. #include <proto/dos.h>
  62. #include <proto/exec.h>
  63.  
  64. /**************************************
  65.         Global Variables
  66. **************************************/
  67.  
  68.  
  69. /**************************************
  70.         Implementation
  71. **************************************/
  72.  
  73. long _main (void)
  74. {
  75.     const char* version = "$VER: Exists 1.0 (03.02.95)";
  76.     long retval = 20;
  77.     struct Library* SysBase = *((struct Library**)4L);
  78.     struct Library* DOSBase;
  79.  
  80.     if (DOSBase = OpenLibrary (DOSNAME, 37)) {
  81.     STRPTR argv[] = { NULL, NULL, NULL };
  82.     APTR   args;
  83.     retval     = 10;
  84.     if (args = (void*)ReadArgs("FILE/A,NAME/S", (LONG*)argv, NULL)) {
  85.         APTR pw;
  86.         struct Process *p;
  87.         BPTR lock;
  88.  
  89.         if ((p = (struct Process *)FindTask(NULL))) {
  90.         pw = p->pr_WindowPtr;
  91.         p->pr_WindowPtr = (APTR)-1;
  92.         } /* if */
  93.  
  94.         /* ---- Existance check: rv==0->Exists, rv==5->n/e */
  95.         retval = 5;
  96.         if ((lock = Lock(argv[0], ACCESS_READ))) {
  97.         retval = 0;
  98.         UnLock (lock);
  99.         } /* if */
  100.  
  101.         /* ----- Result output, either boolean(0/1) or named (name/"") */
  102.         PutStr( retval?
  103.             (STRPTR)( argv[1]? "": "0" ):
  104.             ( argv[1]? argv[0]: (STRPTR)"1" ) );
  105.         PutStr ("\n");
  106.  
  107.         if (p != NULL) {
  108.         p->pr_WindowPtr = pw;
  109.         } /* if */
  110.  
  111.         FreeArgs (args);
  112.     } /* if */
  113.     CloseLibrary (DOSBase);
  114.     } /* if */
  115.     return (retval);
  116. } /* _main */
  117.  
  118. /******************************************************************************
  119. *****  END Exists.c
  120. ******************************************************************************/
  121.  
  122.